<?php
class TsvComponent extends Object{
		
	function AddToDB($fileName,$tableName,$cols){
		
		$sql = "INSERT INTO ".$tableName;
		
		$sqlCols='';
		foreach($cols as $col){
			$sqlCols .= ','.$col;
		}
		if($sqlCols==''){
			return 'need cols';
		}
		$sqlCols=' ('.substr($sqlCols,1).')';
		
		$fileLineArray = file($fileName);
		
		foreach($fileLineArray as $fileLine) {
			$dataLine = trim($fileLine);
			$datas = split("	",$dataLine);
			$sqlValues='';
			foreach($datas as $data){
				$sqlValues .= ",'".$data."'";
			}
			if($sqlValues==''){
				return $fileName."のフォーマットが不正です。";
			}
			$sqlValues = ' VALUES ('.substr($sqlValues,1).')';
			if(!$this->model->query($sql.$sqlCols.$sqlValues)){
				return $fileName."のフォーマットが不正です。";
			}
		}
	}
}
?>
